<?php
ob_clean();
header("content-type:text/html;charset=utf-8");
include_once("/Classes/PHPExcel.php");
$pdo= new PDO("mysql:host=127.0.0.1;dbname=1112","root","root");
$sql="select * from iwebshop_users";
$res=$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$e=new PHPExcel();
$sheet=$e->setActiveSheetIndex(0);
$sheet->setCellValue('A1','ID')
    ->setCellValue('B1','用户名')
    ->setCellValue('C1','密码')
    ->setCellValue('D1','真实姓名')
    ->setCellValue('E1','工资')->getDefaultStyle()->getFont()->setColor(new PHPExcel_Style_Color(
       PHPExcel_Style_Color::COLOR_BLACK
    ));
$i = 2;
foreach ($data as $k => $v)
{
    $sheet->setCellValue('A'.$i,$v['u_id'])
        ->setCellValue("B".$i,$v['u_name'])
        ->setCellValue("C".$i,$v['u_pwd'])
        ->setCellValue("D".$i,$v['u_zname'])
        ->setCellValue("E".$i,$v['u_gong']);
    $i++;
}
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');


$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$objWriter->save('php://output');
exit;

?>